package com.gitee.taotaojs.util.reflect;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;

/**
 * @author TaoTaojs
 * @date 2021/3/1 下午4:09
 * <p>Description</p>
 * <h2>功能描述</h2>
 * 泛型工具类
 * <h3>主要功能：</h3>
 * <ol>
 *     <li>TODO</li>
 * </ol>
 * <h3>关联类</h3>
 * <p>参考链接：</p>
 * <h2>更新日志</h2>
 * [author]        [time]                      [version]          [desc]
 * TaoTaojs        2021/3/1 下午4:09             V1.0
 */

public class GenericityUtil {

    public static void main(String[] args) {
////        List<DemoBean> demoBeans = DemoBean.getList();
//        List<String> demoBeans = new ArrayList<>(){};
//        System.out.println(getActualType(demoBeans, 0));
        BigDecimal bigDecimal = new BigDecimal(7);
        bigDecimal.divide(new BigDecimal(3));
    }

    /**
     * 获取泛型类类型字符串
     */
    public static String getActualType(Object o, int index) {
        Type clazz = o.getClass().getGenericSuperclass();
        ParameterizedType pt = (ParameterizedType) clazz;
        return pt.getActualTypeArguments()[index].toString();
    }

}
